﻿<?php 
	/**
	 * dq187    
	 * index.php
	 * /install
	 *
	 * 大连东丘贸易有限公司
	 * http://www.dq187.com
	 *
	 * Author: Song Dongfang
	 * Date: 2015/06/19
	*/
	
	require (dirname(__FILE__) . '/../include/config.php');
	require (dirname(__FILE__) .  '/include/install.class.php');
	
	$install = new Install();
	
	// 定义安装步骤
	$step = '1';
	$steps = array(
		'1' => '安装协议',
		'2' => '环境检测',
		'3' => '数据库安装',
		'4' => '安装状态',
	);
	// 判断安装步骤
	if(empty($_REQUEST['step']))
	{
		$step = '1';
	}
	else
	{
		$step = trim($_REQUEST['step']);
	}
	
	switch($step)
	{
		case '1':
			include_once('./templates/agreement.php');
			exit();
			break;
		
		case '2':
			include_once('./templates/enviroment.php');
			exit();
			break;
			
		case '3':
			include_once('./templates/settings.php');
			exit();
			break;
		case '4':
			include_once('./templates/complete.php');
			exit();
			break;
	}
	

?>


<?php

	function _dir_path($path) {
		$path = str_replace('\\', '/', $path);
		if (substr($path, -1) != '/')
			$path = $path . '/';
		return $path;
	}

	// 获取客户端IP地址
	function get_client_ip() {
		static $ip = NULL;
		if ($ip !== NULL)
			return $ip;
		if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
			$pos = array_search('unknown', $arr);
			if (false !== $pos)
				unset($arr[$pos]);
			$ip = trim($arr[0]);
		}elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		} elseif (isset($_SERVER['REMOTE_ADDR'])) {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		// IP地址合法验证
		$ip = (false !== ip2long($ip)) ? $ip : '0.0.0.0';
		return $ip;
	}

	function dir_create($path, $mode = 0777) {
		if (is_dir($path))
			return TRUE;
		$ftp_enable = 0;
		$path = _dir_path($path);
		$temp = explode('/', $path);
		$cur_dir = '';
		$max = count($temp) - 1;
		for ($i = 0; $i < $max; $i++) {
			$cur_dir .= $temp[$i] . '/';
			if (@is_dir($cur_dir))
				continue;
			@mkdir($cur_dir, 0777, true);
			@chmod($cur_dir, 0777);
		}
		return is_dir($path);
	}

	function deldir($dir) {
		  //先删除目录下的文件：
		  $dh=opendir($dir);
		  while ($file=readdir($dh)) {
			if($file!="." && $file!="..") {
			  $fullpath=$dir."/".$file;
			  if(!is_dir($fullpath)) {
				  unlink($fullpath);
			  } else {
				deldir($fullpath);
			  }
			}
		  }	 
		  closedir($dh);
		  //删除当前文件夹：
		  if(rmdir($dir)) {
			return true;
		  } else {
			return false;
		  }
	}
?>